package com.rambo.dsd.sys.ws.impl;

import com.rambo.dsd.sys.dao.inter.RoleDao;
import com.rambo.dsd.sys.dao.inter.po.RolePO;
import com.rambo.dsd.sys.ws.inter.RoleWs;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import java.util.List;


@Component
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class RoleWsImpl implements RoleWs {
    @Autowired
    private RoleDao rolePODao;

    @Override
    public RolePO getRole(String id) {
        RolePO rolePO = rolePODao.getByKey(id);
        return rolePO != null ? rolePO : new RolePO();
    }

    @Override
    public List<RolePO> listRole(RolePO rolePO) {
        return rolePODao.findByExample(rolePO);
    }

    @Override
    public List<RolePO> listRoleOrdrBy(RolePO rolePO, String orderby, Boolean asc) {
        return rolePODao.findByExample(rolePO, asc ? Order.asc(orderby) : Order.desc(orderby));
    }

    @Override
    public RolePO addRole(RolePO rolePO) {
        return rolePODao.add(rolePO);
    }

    @Override
    public RolePO updateRole(RolePO rolePO) {
        return rolePODao.edit(rolePO);
    }

}